CATMainPage = function(){
	var page = this;
	//pindex : section, (testing | testing_skip)
	this.pindex = 'section';
	
	this.sectionList = new SectionList(this);
	this.startPage = new StartPage(this);
	this.itemPage = new ItemPage(this);

	this.tbarRightButton = new Ext.Button({
		id: 'exam_toolbar_right_btn',
		text: 'Next',
		ui: 'forward',
		hidden: true,
		handler : function(button, event){
			if(page.pindex == 'section'){
				page.setHeaderTitle(userProfile.getSectionName());
				page.sectionList.hide(true);
				page.startPage.show(true);
				
				page.tbarRightButton.hide(true);
				page.tbarLeftButton.show(true);
			}else if(page.pindex == 'testing' || page.pindex == 'testing_skip'){
				page.itemPage.nextItem(true);
			}
		}
	});
	
	this.tbarLeftButton = new Ext.Button({
		id: 'exam_toolbar_left_btn',
		text: 'Back',
		ui: 'back',
		hidden: true,
		handler : function(button, event){
			if(page.pindex == 'section'){
				page.setHeaderTitle('Select Section');
				page.startPage.hide(true);
				page.sectionList.show(true);

				page.tbarLeftButton.hide(true);
				page.tbarRightButton.show(true);
			}
		}
	});
	
	this.tbar = new Ext.Toolbar({
		id: 'exam_toolbar',
		xtype: 'toolbar',
		title: 'Select Section',
        ui: 'light',
		dock: 'top',
        items: [this.tbarLeftButton, {xtype: 'spacer'}, this.tbarRightButton]
	});
	
	CATMainPage.superclass.constructor.call(this, {
		id: 'exam_main',
		dockedItems: this.tbar,
		// autoHeight: true,
		fullscreen: true,
	    items: [this.sectionList, this.startPage, this.itemPage]
	});
	
	this.sectionList.show(true);
	this.startPage.hide(true);
	this.itemPage.hide(true);
};

Ext.extend(CATMainPage, Ext.Panel, {
	setHeaderTitle: function(title){
		this.tbar.setTitle(title);
	},
	setPIndex: function(name){
		this.pindex = name;
		if(this.pindex == 'testing'){
			this.tbarRightButton.setText('Next');
			this.tbarRightButton.show(true);
			this.tbarLeftButton.hide(true);
			
		}else if(this.pindex == 'testing_skip'){
			this.tbarRightButton.hide(true);
			this.tbarLeftButton.hide(true);
		}else if(this.pindex == 'section'){
			this.tbarRightButton.setText('Next');
		}
	},
	startCAT: function(){
		this.sectionList.hide(true);
		this.startPage.hide(true);
		this.itemPage.nextItem(false);
		desabledDock(true);
	},
	stopCAT: function(){
		this.sectionList.deselect(userProfile.getSection());
		this.setPIndex('section');
		this.sectionList.show(true);
		this.startPage.hide(true);
		this.itemPage.hide(true);
		userProfile.setSection(null);
		userProfile.setTheta(0.0);
		desabledDock(false);
		setActiveDockItem(1);
	}
});